<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/view/common/kendocommon.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title>预算</title>
    <meta charset="utf-8">
    <style>
    	table{font-size:12px}
    </style>
    <script>
        $(function() {
            var dataSource = new kendo.data.DataSource({
                transport: {
                    read:  {
                        url: "${path}/budget/queryData?reportID=${reportID}&reportDate=${reportDate}",
                        dataType: "json",
                    }
                },
                serverFiltering: true,
                schema: {
                	data:"data",
               		total:"total",
               		${hasitem}
                }
            });
            
            $("#grid").kendoGrid({
                dataSource: dataSource,
                selectable: "multiple row",
                allowCopy: true,
                editable: 'incell',
                columns: [${element}]
            });
            
            $('#grid').css("height",document.body.clientHeight-5);
            
		});
		
		var reflashReport = function(){//查询
			$("#grid").data("kendoGrid").dataSource.fetch();
		}
		
		var saveReport = function(){
			var dataArr = new Array();
			var item_0 = {reportID:'${reportID}',reportDate:'${reportDate}',reportUnit:'${reportUnit}'};
			dataArr.push(item_0);
			var grid = $("#grid").data("kendoGrid");
			$.each(grid.items(), function (i, item) {
				dataArr.push(grid.dataItem(item));
			});
			//console.log(JSON.stringify(dataArr));
			$.ajax({
		        url: "${path}/budget/saveBudget",
		        dataType: 'json',
   				contentType: "application/json",
		        data: JSON.stringify(dataArr),
		        type:"POST", 
		        success: function (text) {
		        	$("#grid").data("kendoGrid").dataSource.fetch();
		        	toastr.info(text.msg, "提示", toastrOptsBottom);
		        },
		        error: function (jqXHR, textStatus, errorThrown) {
		        	toastr.info("与远程服务器交互异常，请规范操作或重新登录", "提示", toastrOptsBottom);
		        }
		    });
		}
		
    </script>
</head>
<body>
    <div id="grid" style="margin:2px;font-size:10px"></div>
</body>
</html>
